home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / lib / mntlib44.zoo / mntlib / lattice / crt0.s < prev    next >
Text File  |  1993-10-12  |  3KB  |  136 lines

  1.     INCLUDE    inc.i
  2.  
  3. _PRG    EQU    1    ; Default...
  4. _ACC    EQU    0
  5. _AUT    EQU    0
  6.  
  7.     IFD    ACC
  8. _ACC    EQU    1
  9. _PRG    EQU 0
  10.     ELSE
  11.  
  12.     IFD    AUT
  13. _AUT    EQU    1
  14. _ACC    EQU 1
  15.     ENDC
  16.     ENDC    ; !ACC
  17.     
  18. ;
  19. ; Initilization code; this is common to both 16 and 32 bit libraries,
  20. ; so be careful!
  21. ;
  22.     INFO
  23.     xref    __app        ; short, declared in crtinit.c
  24.     xref    __base        ; BASEPAGE *, declared in crtinit.c
  25.     xref    __heapbase    ; void *
  26.     xref    __stksize    ; long, declared by user or in stack.c
  27.     
  28.     IF    _BASREL
  29.     FINFO
  30.     xref    __LinkerDB
  31.     ENDC
  32.     
  33.     CODE
  34.     IF    _REGARG
  35.     xdef    @_start
  36.     xref    @_acc_main
  37.     xref    @_crtinit
  38. @_start:
  39.     ELSE
  40.     xdef    __start
  41.     xref    __acc_main
  42.     xref    __crtinit
  43. __start:
  44.     ENDC
  45.     
  46.     
  47. ;
  48. ; Assumption: basepage is passed in a0 for accessories; for programs
  49. ; a0 is always 0.
  50.  
  51.     IF    _BASREL
  52.     lea    __LinkerDB,a4
  53.     ENDC
  54.     sub.l    a6,a6        ; clear a6 for debuggers
  55.     IF    _AUT
  56.     cmp.w    #0,a0        ; test if acc or program
  57.     beq.s    __startprg    ; if a program, go elsewhere
  58.     tst.l    36(a0)        ; also test parent basepage pointer
  59.     bne.s    __startprg    ; for acc's, it must be 0
  60.     ENDC
  61.     IF    _ACC
  62.     move.l    a0,__base    ; acc basepage is in A0
  63.     move.l    __heapbase,sp    ; stack must be set from heap
  64.     add.l    __stksize,sp
  65.     IF    _REGARG
  66.     bra    @_acc_main
  67.     ELSE
  68.     bra    __acc_main    ; function is in crtinit.c
  69.     ENDC
  70.     ENDC
  71. ;
  72. ; program startup code: doesn't actually do much, other than push
  73. ; the basepage onto the stack and call _start1 in crtinit.c
  74. ;
  75.     IF    _PRG
  76. __startprg:
  77.     move.l    4(sp),a0    ; get basepage
  78.     move.l    a0,__base    ; save it
  79.     move.l    4(a0),d0    ; get _base->p_hitpa
  80.     bclr    #$0,d0        ; round off
  81.     move.l    d0,sp        ; set stack (temporarily)
  82.     IF    _REGARG
  83.     bra    @_crtinit
  84.     ELSE
  85.     bra    __crtinit    ; in crtinit.c
  86.     ENDC
  87.     ENDC
  88.  
  89. ;
  90. ; _setstack: changes the stack pointer; called as
  91. ;     void setstack( void *newsp )
  92. ; called from crtinit.c once the new stack size has been decided upon
  93. ;
  94. ; WARNING WARNING WARNING: after you do this, local variables may no longer
  95. ; be accessible!
  96. ; destroys a1 and a7
  97.  
  98.     IF    _REGARG
  99.     xdef    @_setstack
  100. @_setstack:
  101.     ELSE
  102.     xdef    __setstack
  103. __setstack:
  104.     ENDC
  105.     
  106.     move.l    (sp)+,a1    ; save return address
  107.     IF    _REGARG
  108.     move.l    a0,sp        ; new stack pointer - from register
  109.     ELSE
  110.     move.l    (sp)+,sp    ; new stack pointer - from stack
  111.     ENDC
  112.     subq.l    #4,sp        ; fixup for tidy upon return
  113.     jmp    (a1)        ; back to caller
  114.  
  115. ;
  116. ; interfaces for gprof: for crt0.s, does nothing, but for gcrt0.s branches
  117. ; to the appropriate subroutines
  118. ;
  119.     IF    _REGARG
  120.     xdef    @_monstartup
  121.     xdef    @_moncontrol
  122.     xdef    @__mcleanup
  123. @_monstartup:
  124. @_moncontrol:
  125. @__mcleanup:
  126.     ELSE
  127.     xdef     __monstartup
  128.     xdef    __moncontrol
  129.     xdef     ___mcleanup
  130. __monstartup:
  131. __moncontrol:
  132. ___mcleanup:
  133.     ENDC
  134.     rts
  135.     end
  136.